<?php

    require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'engine'.DIRECTORY_SEPARATOR.'framework.php';

    sys::addPlugin("OutputEncode");

    sys::header('Content-Type: text/html; carset=UTF-8');
    include dirname(__FILE__).DIRECTORY_SEPARATOR.'fsactions.php';

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>File Browser</title>
    <style></style>
</head>
<body>
		<table><tr>
		<td><a href="?action=prev">Back</a></td>
		<td><a href="?action=next">Next</a></td>
		<td><a href="?action=top">Top</a></td>
		</tr>
		</table>
		<?php 


		if (Session::getParam('pwd') !== '/') {
		    $path = explode('/', Session::getParam('pwd'));
		    array_shift($path);
		} else {
			$path = array();
		}

    $origin_path = array();
    $this_path_array = $path;

    foreach ($path as &$value) {
    	$origin_path[] = array_shift($this_path_array);
    	$value = array(
    		'path' => '/'.implode('/', $origin_path),
    		'name' => $value,
    	);
    }
    array_unshift($path, array(
    		'path' => '/',
    		'name' => '#',
    	));

    $this_dir = array_pop($path);
    foreach ($path as &$dir) {
    	$dir = '<a href="'.htmlspecialchars('?action=cd&param='.
    		urlencode($dir['path'])).'">'.
    		htmlspecialchars($dir['name']).
    	'</a>';
    }
    $path[] = htmlspecialchars($this_dir['name']);

    echo implode('/', $path);

    ?><table><?php 
    foreach ($Files as $file) {
    	echo '<tr><td>';
    	if ($file['type'] == 'dir') {
			echo '<a href="'.htmlspecialchars('?action=cd&param='.urlencode($file['path'].($file['path'] != '/' ? '/' : '').$file['name'])).'">'.htmlspecialchars($file['name']).'</a>';
    	} else {
    		echo $file['name'];
        }
    	echo '</td>';
    	echo '<td></td>';
    	echo '</tr>';
    }
    ?>
    </table>


</body>
</html>